package com.example.myapplication.old.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;
import com.example.myapplication.old.entity.Game;

import java.util.List;

public class GameAdapter extends RecyclerView.Adapter<GameAdapter.GameHolder>  {
    private List<Game> gamelist;

    public void setData(List<Game> gamelist){
        this.gamelist=gamelist;
        notifyDataSetChanged();
    }

    public GameAdapter() {
    }

    @NonNull
    @Override
    public GameHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_game,parent,false);
        return new GameHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull GameHolder holder, int position) {
        Game game = gamelist.get(position);
        holder.number.setText(game.getNumber()+"");
        holder.img.setImageResource(game.getImg());
        holder.name.setText(game.getName());
        holder.size.setText(game.getSize());
        holder.count.setText(game.getCount());
    }

    @Override
    public int getItemCount() {
        return gamelist == null? 0 : gamelist.size();
    }

    class GameHolder extends RecyclerView.ViewHolder{
        TextView number;
        ImageView img;
        TextView name;
        TextView size;
        TextView count;
        public GameHolder(@NonNull View itemView) {
            super(itemView);
            number = itemView.findViewById(R.id.number);
            img = itemView.findViewById(R.id.game_img);
            name = itemView.findViewById(R.id.game_name);
            size = itemView.findViewById(R.id.game_size);
            count = itemView.findViewById(R.id.game_count);
        }
    }
}
